package com.sohoometer.base.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.nari.baseinfo.model.IBuilding;
import com.nari.baseinfo.model.ICommunity;
import com.nari.baseinfo.model.IProject;
import com.nari.baseinfo.service.IBuildingService;
import com.nari.baseinfo.service.ICommunityService;
import com.nari.baseinfo.service.IProjectService;
import com.nari.basic.model.IUser;
import com.nari.coreframe.action.struts2.JSONActionSupport;
import com.nari.platform.model.PageCond;
import com.nari.platform.model.WebConstants;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.util.ValueStack;
import com.sohoometer.base.dao.BaseDao;

public class BaseAction  extends JSONActionSupport{
	private static final long serialVersionUID = 8521152666276722681L;
	protected String projectUID;
	protected String communityUID;
	protected String buildingUID;
	protected List<IProject> projectList;
	protected List<ICommunity> communityList;
	protected List<IBuilding> buildingList;
	protected Map<String, String> infoMap; 
	protected PageCond pageCond;
	protected int pageIndex = 1; // 默认查询第一页列表
	protected int pageSize;//
	@Autowired
	protected IProjectService iProjectService;
	@Autowired
	protected ICommunityService iCommunityService;
	@Autowired
	protected IBuildingService iBuildingService;
	@Autowired
	protected BaseDao baseDao;

	 public void queryConditionList() throws Exception{
			//所属项目列表
			this.projectList = this.iProjectService.queryAllProjectInOrder();
			if(this.projectList == null) {
				this.projectList = new ArrayList<IProject>();
			}
			//所属小区列表
			if(this.projectUID!=null && !"".equals(projectUID)) {
				this.communityList = this.iCommunityService.queryCommunitysByBelongings(null, null, null, projectUID);
			} else {
				this.communityList = new ArrayList<ICommunity>();
			}
			//所属楼栋列表
			this.buildingList = this.iBuildingService.queryBuildingByBelongings(projectUID, communityUID);
	 }
	 
	 public void queryMap() {
		  infoMap = baseDao.queryIdMap();
	 } 
	
	 /**
	  * 将某对象压入栈顶转化为JSON传给前台
	  * @param object 用于压栈的对象
	  * */
	 public void pushStack(Object object) {
		 ActionContext context = ActionContext.getContext();
		 ValueStack valueStack = context.getValueStack();
		 valueStack.push(object);
	 }
	 
	 public Map<String, Object>  getSession() {
		 	ActionContext context = ActionContext.getContext();
		 	return context.getSession();
	 }
	 public IUser  getUser() {
		 return  (IUser) getSession().get(WebConstants.USER_SESSION);
	 }
 	public String getProjectUID() {
		return projectUID;
	}
	public void setProjectUID(String projectUID) {
		this.projectUID = projectUID;
	}
	public String getCommunityUID() {
		return communityUID;
	}
	public void setCommunityUID(String communityUID) {
		this.communityUID = communityUID;
	}
	public String getBuildingUID() {
		return buildingUID;
	}
	public void setBuildingUID(String buildingUID) {
		this.buildingUID = buildingUID;
	}
	public List<IProject> getProjectList() {
		return projectList;
	}
	public void setProjectList(List<IProject> projectList) {
		this.projectList = projectList;
	}
	public List<ICommunity> getCommunityList() {
		return communityList;
	}
	public void setCommunityList(List<ICommunity> communityList) {
		this.communityList = communityList;
	}
	public List<IBuilding> getBuildingList() {
		return buildingList;
	}
	public void setBuildingList(List<IBuilding> buildingList) {
		this.buildingList = buildingList;
	}
	public Map<String, String> getInfoMap() {
		return infoMap;
	}
	public void setInfoMap(Map<String, String> infoMap) {
		this.infoMap = infoMap;
	}
	public PageCond getPageCond() {
		return pageCond;
	}
	public void setPageCond(PageCond pageCond) {
		this.pageCond = pageCond;
	}
	public int getPageIndex() {
		return pageIndex;
	}
	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	
}
